package 
{
	import com.furusystems.messaging.pimp.IMessageReceiver;
	import com.furusystems.messaging.pimp.Message;
	import com.furusystems.messaging.pimp.MessageData;
	import com.furusystems.messaging.pimp.PimpCentral;
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * Simple testbed
	 * @author Andreas Ronning
	 */
	public class PimpMain extends Sprite implements IMessageReceiver
	{
		
		public function PimpMain():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			PimpCentral.addReceiver(this, TestMessages.TEST_ONE, TestMessages.TEST_TWO);
			
			PimpCentral.addCallback(TestMessages.TEST_ONE, onTestOne);
			
			PimpCentral.send(TestMessages.TEST_ONE,"hooray");
			PimpCentral.send(TestMessages.TEST_TWO, "yeehaw");
			
		}	
		
		private function onTestOne(dataObject:MessageData):void 
		{
			trace("Test one! ", dataObject.data);
		}
		
		/* INTERFACE no.doomsday.messaging.pimp.IMessageReceiver */
		
		public function onMessage(dataObject:MessageData):void 
		{
			trace("Received message " + dataObject.message + " with payload: "+dataObject.data);
		}
		
	}
	
}